<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="viewport" id="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no"/>
<link href="/static/webAPP/css/reset.css" rel="stylesheet" type="text/css">
<link href="/static/webAPP/css/indent-details.css" rel="stylesheet" type="text/css">
<script src="/static/webAPP/lib/mobile/layer.js"></script>
<title>申请退款</title>
<style>
.zjzz-buylist-btn_c {
	float: right;
	width: 50%;
	margin-right: 10px;
	margin-top: 10px;
}
.zjzz-buylist-btn_c li {
	float: right;
	width: 40%;
	font-size: 14px;
	text-align: center;
	line-height: 25px;
	border-radius: 3px;
}
.zjzz-buylist-btn3 {
	color: #FFFFFF;
	background: #FF9201;
	border: 1px solid #FF9201;
}
</style>
</head>
<body>
<div class="near-box">
    <a href="javascript:history.go(-1);" class="jd-qrdd-topbox">申请退款</a>
    <div class="jd-qrdd-bigbox">
        <!--商品地址管理部分-->
        <div class="indent-details-box">
            <span class="indent-details-img1"></span>
            <span class="indent-details-text1 order_status"></span>
            <span class="indent-details-text2">订单编号：<i class="order_number"></i></span>
            <span class="indent-details-text3"></span>
        </div>
        
        <!--商品部分-->
        <div class="zjzz-buylist-goods1">
            
        </div>
        <!--商品金额部分-->
        <div class="indent-details-box2">
            <span class="indent-details-text4">总金额</span>
            <span class="indent-details-text5">￥<i class="order_amount"></i></span>
        </div>
        
        <!--订单编号部分-->
        <div class="indent-details-box3">
            <!-- <p>订单编号:<i class="order_number"></i></p> -->
            <p>备注:<i class="order_remarks"></i></p>
        </div>

        <div class="indent-details-box3">
            <textarea name="" id="refund_reason_txt" cols="45" rows="4" placeholder="输入退款原因" required ></textarea>
        </div>
        <div class="zjzz-buylist-btn_c"><li class="zjzz-buylist-btn3 refund_reason_btn">确认退款</li></div>
    </div>
</div>

<script src="/static/webAPP/js/jquery-1.8.3.min.js"></script>
<script>
$(function(){
    var oid = getUrlParam('id')
    var userName = sessionStorage.getItem("sessionName")
    $.ajax({
        type: "post",
							//TODO:
        url: "/app/bookOrder/getOrderDetail",
        data: {order_id: oid},
        dataType: "json",
        success: function(mag){
            if (mag.success == true) {
                $(".order_status").html(isStatus(mag.data.order_status))
                $(".order_number").html(mag.data.id)
                $(".indent-details-text3").html('订单时间：' + timestampToTime(mag.data.create_date))
                $(".order_remarks").html(mag.data.comment)
                $(".order_amount").html(mag.data.amount)
                var tag = ''
                for (let i = 0; i < mag.data.commodities.length; i++) {
                    var tag1 = '<div class="zjzz-buylist-det"><div class="zjzz-buylist-gdetail"><span class="zjzz-buylist-gtit1">'+ mag.data.commodities[i].commodityName +'</span><span class="zjzz-buylist-gmoney"><i class="zjzz-buylist-gm1">￥'+ mag.data.commodities[i].price +'</i><i class="zjzz-buylist-gm2">'+ mag.data.commodities[i].specifications +'</i><i class="zjzz-buylist-gm2">x'+ mag.data.commodities[i].count +'</i></span></div></div>'
                    tag += tag1
                }
                $(".zjzz-buylist-goods1").html(tag)
            }
        }
    })


    $(".refund_reason_btn").on("click",function(){
        // var user_id =
        var reason = $("#refund_reason_txt").val()
        if (reason == '' || reason == undefined || reason == null) {
            layer.open({
                content: '请填写退款原因',
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
        } else {
            var refund_reason = $("#refund_reason_txt").val()
            $.ajax({
                type: "get",
                                //TODO:
                url: "/app/userInfo/" + userName,
                data: '',
                dataType: "json",
                success: function(mag){
                    var user_id = mag.data.id
                    $.ajax({
                        type: "post",
                                //TODO:
                        url: "/app/bookOrder/applyForRefundBookOrder",
                        data: {bookOrderId: oid,refund_reason: refund_reason,user_id: user_id},
                        dataType: "json",
                        success: function(res){
                            layer.open({
                                content: res.data,
                                skin: 'msg',
                                time: 2 //2秒后自动关闭
                            });
                            setTimeout(function(){ window.location.href="./my-indent-dfh.html"; }, 2000);
                        }
                    })
                },
                error:function(){
                    layer.open({
                        content: '状态失效，请重新登录',
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                }
            })
        }
        
    })
})

    //获取后台传参
function getUrlParam(name) {
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
 }

 function timestampToTime(timestamp) {
    var date = new Date(timestamp * 1);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate()) + ' ';
    h = (date.getHours() < 10 ? '0' +date.getHours() : date.getHours()) + ':';
    m = (date.getMinutes() < 10 ? '0' +date.getMinutes() : date.getMinutes()) + ':';
    s = (date.getSeconds() < 10 ? '0' +date.getSeconds() : date.getSeconds());
    return Y+M+D+h+m+s;
 }
function isStatus(num) {
    if (num == 0) {
        return '待付款'
    }else if (num == 1) {
        return '待发货'
    }else if (num == 2) {
        return '待收货'
    // }else if (num == 3) {
    //     return '待评价'
    }else if (num == 6) {
        return '订单取消'
    }else if (num == 8) {
        return '付款订单取消'
    }else{
        return '已完成'
    }
}
</script>
</body>

</html>